<?php

if (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".inc.php",$_SERVER['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}


		
// get listing options		
$getListOptions = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'prodListings'");
$listOptions = mysql_fetch_assoc($getListOptions);
$prodOptions = explode(":", $listOptions['value']);


if (isset($_GET['pid'])) {
	
// use merchant product ids
	if ($navOpt[12] == 1) {
	$theprodID = 'merchantProdID';
	} else {
	$theprodID = 'dbProdID';
	}
// get details of single product
$sql = sprintf("SELECT * FROM affiliSt_products1 WHERE prodDB = %d AND $theprodID = %s",
			quote_smart($_GET['proddb']),
			quote_smart($_GET['pid']));
$getPDetails = mysql_query($sql, $databaseConnect) or die(mysql_error());
$pDetails = mysql_fetch_assoc($getPDetails);



// get keywords
$pieces = explode(" ", str_replace($allCharacters, "", $pDetails['prodName']));
$kp = count($pieces);
// reset pieces
$pluspieces = '';
for ($pi=0;$pi<$kp;$pi++) {
$pluspieces .= $pieces[$pi].' ';
}
$pluspieces = rtrim($pluspieces, " ");

// output search results
$dbcondition = '';
if ($indcount == 0) {
$sql = "SELECT *, ( (1.3 * (MATCH(prodName) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) + (0.6 * (MATCH(prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) ) AS relevance FROM affiliSt_products1 WHERE ( MATCH(prodName,prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE) ) HAVING relevance > 0 AND dbProdID != '".$pDetails['dbProdID']."' ORDER BY relevance DESC LIMIT 0, ".$maxRows_product."";
} else {
$sql = "SELECT * FROM affiliSt_products1 WHERE MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") AND dbProdID != '".$pDetails['dbProdID']."' LIMIT 0, ".$maxRows_product."";
}
$getSimilar = mysql_query($sql, $databaseConnect) or die(mysql_error());
$similar = mysql_fetch_assoc($getSimilar);


$box_content = new XTemplate ("skins/".$configSkin['value']."/styleTemplates/products.tpl");

if ($similar['dbProdID'] != NULL && $navOpt[11] == 1) {

// pinch column values from head
$totalColumns = $pPerPage[2];
$columnCount = 0;
$productCount = 0;

        do {
		
			
		// get titles
		$getTitles = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'feedMemory".$similar['prodDB']."'");
		$allTitles = mysql_fetch_assoc($getTitles);
		$listTitles = explode("-:-", $allTitles['value']);
		
		// thumb image
		if ($similar['prodImageSmall'] == NULL) {
		$thumbImage = $similar['prodImageURL'];
		} else {
		$thumbImage = $similar['prodImageSmall'];
		}
		
		
					// use merchant product ids
					if ($navOpt[12] == 1) {
					$theprodID = $similar['merchantProdID'];
					} else {
					$theprodID = $similar['dbProdID'];
					}
					if ($navOpt[7] == 1) {
					// html perma
					$prodLink = $installDir['value'].'product/'.$similar['prodDB'].'/'.$theprodID.'/'.urltxt($similar['prodName']).'.html';
					$savelink = $installDir['value'].'saveproduct/'.$similar['prodDB'].'/'.$theprodID.'/'.urltxt($similar['prodName']).'.html';
					$box_content->assign("IMAGELINK",$installDir['value'].'img/'.$similar['prodDB'].'/'.$similar['dbProdID'].'.jpg');
					} else {
					// php link
					$prodLink = $installDir['value'].'index.php?case=product&proddb='.$similar['prodDB'].'&pid='.$theprodID;
					$savelink = $installDir['value'].'index.php?case=product&proddb='.$similar['prodDB'].'&pid='.$theprodID.'&savelink=true';
					$box_content->assign("IMAGELINK",$thumbImage);
					}
					$box_content->assign("PRODLINK",$prodLink);
					
					// add to saved list link
					$box_content->assign("SAVELINK",'<a href="'.$savelink.'" rel="nofollow">+ Add to my saved list</a><br />');
					
					$box_content->assign("GOLINK",$installDir['value'].'go.php?proddb='.$similar['prodDB'].'&amp;l='.$similar['dbProdID']);
					if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[21];
						} else {
						$theTitle = '';
						}
					$box_content->assign("NAME",$theTitle.$similar['prodName']);
					
					if ($prodOptions[0] == 1 && $similar['merchant'] != '') {
					$box_content->assign("MERCHANT",'<span class="styleProdMerchant">'.$similar['merchant'].'</span><br />');
					}
					if ($prodOptions[1] == 1 && $similar['merchantProdID'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[19];
						} else {
						$theTitle = '';
						}
					$box_content->assign("PRODID", '<span class="styleProdID">'.$theTitle.$similar['merchantProdID'].'</span><br />');
					} else {
					$box_content->assign("PRODID",'');
					}
					if ($prodOptions[2] == 1 && $similar['prodCategory'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[20];
						} else {
						$theTitle = '';
						}
					$box_content->assign("PRODCAT",'<span class="styleProdCategory">'.$theTitle.$similar['prodCategory'].'</span><br />');
					} else {
					$box_content->assign("PRODCAT",'');
					}
					if ($prodOptions[3] == 1 && $similar['prodBrand'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[22];
						} else {
						$theTitle = '';
						}
					$box_content->assign("BRAND",'<span class="styleProdBrand">'.$theTitle.$similar['prodBrand'].'</span><br />');
					} else {
					$box_content->assign("BRAND",'');
					}
					if ($prodOptions[4] == 1 && $similar['prodPromoText'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[24];
						} else {
						$theTitle = '';
						}
					$box_content->assign("PROMO",'<span class="styleProdPromo">'.$theTitle.$similar['prodPromoText'].'</span><br />');
					} else {
					$box_content->assign("PROMO",'');
					}
					if ($prodOptions[5] == 1 && $similar['prodDescription'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[23];
						} else {
						$theTitle = '';
						}
					$box_content->assign("DESCRIPTION",'<span class="styleProdDescription">'.$theTitle.$similar['prodDescription'].'</span><br />');
					} else {
					$box_content->assign("DESCRIPTION",'');
					}
					if ($prodOptions[6] == 1 && $similar['prodPrice'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[27];
						} else {
						$theTitle = '';
						}
						if ($similar['prodPrice'] == 0.00) {
						$box_content->assign("PRICE",$theTitle.'<span class="styleProdPrice">N/A</span><br />');
						} else {
						$box_content->assign("PRICE",$theTitle.'<span class="styleProdPrice">'.$similar['prodCurrency'].$similar['prodPrice'].'</span><br />');
						}
					} else {
					$box_content->assign("PRICE",'');
					}
					if ($prodOptions[7] == 1 && $similar['extraFieldA'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[28];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDA",'<span class="singleProdDescription">'.$theTitle.$similar['extraFieldA'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDA",'');
					}
					if ($prodOptions[8] == 1 && $similar['extraFieldB'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[29];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDB",'<span class="singleProdDescription">'.$theTitle.$similar['extraFieldB'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDB",'');
					}
					if ($prodOptions[9] == 1 && $similar['extraFieldC'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[30];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDC",'<span class="singleProdDescription">'.$theTitle.$similar['extraFieldC'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDC",'');
					}
					if ($prodOptions[10] == 1 && $similar['extraFieldD'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[31];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDD",'<span class="singleProdDescription">'.$theTitle.$similar['extraFieldD'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDD",'');
					}
					if ($prodOptions[11] == 1 && $similar['extraFieldE'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[32];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDE",'<span class="singleProdDescription">'.$theTitle.$similar['extraFieldE'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDE",'');
					}
					if ($prodOptions[13] == 1 && $listTitles[33] != '') {
					$box_content->assign("MERCHANTLOGO",'<a href="'.$installDir['value'].'go.php?proddb='.$similar['prodDB'].'&amp;l='.$similar['dbProdID'].'" rel="nofollow" target="_blank"><img src="'.$installDir['value'].$listTitles[33].'" alt="'.$similar['merchant'].'" border="0" /></a><br />');
					} else {
					$box_content->assign("MERCHANTLOGO",'');
					}
					$box_content->assign("INSTALLDIR",$installDir['value']);
					$box_content->assign("SKIN",$configSkin['value']);
					$box_content->assign("ENDROW","");
					
					if ($navOpt[13] == 1) {
					// get comments
					$getComments = mysql_query("SELECT * FROM affiliSt_comments WHERE attachedID = '".$similar['prodName']."' AND approve = '1' AND section = 'products' ORDER BY date DESC");
					$comments = mysql_fetch_assoc($getComments);
					// total comments
					$sql = "SELECT count(*) as numRows FROM affiliSt_comments WHERE  attachedID = '".$similar['prodName']."' AND approve = '1' AND section = 'products'";
					$query = mysql_query($sql);
					$aRow = mysql_fetch_array($query);
					//echo $aRow[numRows]
					
					$totalProdRating = 0;
						do {
						$totalProdRating = $totalProdRating + $comments['rating'];
						} while ($comments = mysql_fetch_assoc($getComments));
					
						if ($aRow[numRows] != 0) {
						$prodRating = $totalProdRating / $aRow[numRows];
						$prodRating = round($prodRating);
						}
					
						if ($aRow[numRows] == 0) {
						$box_content->assign("RATING",'<a href="'.$prodLink.'">Review this product</a><br />');
						} else {
						$box_content->assign("RATING",'<img src="'.$installDir['value'].'skins/'.$configSkin['value'].'/styleImages/'.$prodRating.'star.gif" width="84" height="15" alt="Rating: '.$prodRating.'" align="left" /> (<a href="'.$prodLink.'">'.$aRow[numRows].' reviews</a>)<br />');
						}
					
						if ((($prodOptions[13] == 1 && $listTitles[33] != '') || ($prodOptions[0] == 1 && $similar['merchant'] != ''))) {
						// merchant comments
						$getMerchantComments = mysql_query("SELECT * FROM affiliSt_comments WHERE attachedID = '".urltxt($similar['merchant'])."' AND approve = '1' AND section = 'stores' ORDER BY date DESC");
						$merchantComments = mysql_fetch_assoc($getMerchantComments);
						// total comments
						$sql = "SELECT count(*) as numRows FROM affiliSt_comments WHERE attachedID = '".urltxt($similar['merchant'])."' AND approve = '1' AND section = 'stores'";
						$query = mysql_query($sql);
						$aRow = mysql_fetch_array($query);
						//echo $aRow[numRows]
						
						$totalMerchantRating = 0;
							do {
							$totalMerchantRating = $totalMerchantRating + $merchantComments['rating'];
							} while ($merchantComments = mysql_fetch_assoc($getMerchantComments));
						
							if ($aRow[numRows] != 0) {
							$merchantRating = $totalMerchantRating / $aRow[numRows];
							$merchantRating = round($merchantRating);
							}
						
							if ($navOpt[7] == 1) {
							// html perma
							$merchantLink = $installDir['value'].'stores/'.urltxt($similar['merchant']).'.html';
							} else {
							// php link
							$merchantLink = $installDir['value'].'index.php?case=stores&merchant='.urltxt($similar['merchant']);
							}
							if ($aRow[numRows] == 0) {
							$box_content->assign("MERCHANTRATING",'<a href="'.$merchantLink.'">Review this store</a><br />');
							} else {
							$box_content->assign("MERCHANTRATING",'<img src="'.$installDir['value'].'skins/'.$configSkin['value'].'/styleImages/'.$merchantRating.'tic.gif" width="84" height="15" alt="Rating: '.$merchantRating.'" /><br />(<a href="'.$merchantLink.'">'.$aRow[numRows].' reviews</a>)<br />');
							}
						} else {
							$box_content->assign("MERCHANTRATING",'');
						}
					}
					
					
					
					$columnCount++;
					$productCount++;
					if ($columnCount == $totalColumns && $productCount != $maxRows_product) {
					$box_content->assign("ENDROW","</tr>\n<tr>");
					$columnCount = 0;
					}
					
					$box_content->parse("prod.td");
		
        } while ($similar = mysql_fetch_assoc($getSimilar));
		
		$box_content->assign("SIMILARTITLE",'<p><strong>Similar Products</strong></p>');

$box_content->parse("prod");
$box_content = $box_content->text("prod");

} else {
$box_content->parse("nosimilarprod");
$box_content = $box_content->text("nosimilarprod");
}








} else {

$box_content = new XTemplate ("skins/".$configSkin['value']."/styleTemplates/products.tpl");

if ($row_product['prodID'] != NULL) {










// refine search categories
	if (isset($_GET['ps'])) {
	
	// get keywords
	$pieces = explode(" ", strip_tags($_GET['ps']));
	$kp = count($pieces);
	// reset pieces
	$pluspieces = '';
	for ($pi=0;$pi<$kp;$pi++) {
	$pluspieces .= $pieces[$pi].' ';
	}
	$pluspieces = rtrim($pluspieces, " ");
	
	// output search results
	if ($indcount == 0) {
	$sql = "SELECT prodCategory, ( (1.3 * (MATCH(prodName) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) + (0.6 * (MATCH(prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) ) AS relevance FROM affiliSt_products1 WHERE ( MATCH(prodName,prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE) ) HAVING relevance > 0 ORDER BY prodCategory ASC";
	} else {
	$sql = "SELECT prodCategory, MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") AS relevance FROM affiliSt_products1 WHERE MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") HAVING relevance > 0 ORDER BY prodCategory ASC";
	}
	
	
	$getRefineCategory = mysql_query($sql, $databaseConnect) or die(mysql_error());
	$refineCategory = mysql_fetch_assoc($getRefineCategory);
	$storedCategory = '';
	
	$count = 0;

		do { 
		$refcatresult = ucwords(strtolower($refineCategory['prodCategory']));
			if ($storedCategory != $refcatresult && $refcatresult != NULL) {
			
				if (isset($_GET['rshow'])) {
				$rshow = '&rshow=all';
				} else {
				$rshow = '';
				}
			
			$box_content->assign("REFLINKDATA",$installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).'&pscat='.str_replace(" ", "+", $refcatresult).$rshow);
			$box_content->assign("REFINE",$refcatresult);
			$box_content->parse("prod.refine.li");
			
				if ($count >= 3 && !isset($_GET['rshow'])) {
				$box_content->assign("REFLINKDATA",$installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).'&rshow=all');
				$box_content->assign("REFINE",'More...');
				$box_content->parse("prod.refine.li");
				break;
				}
				
			$storedCategory = $refcatresult;
			} else {
			$refcatresult = ucwords(strtolower($refineCategory['prodCategory']));
			}
			
			$count++;
		
		} while ($refineCategory = mysql_fetch_assoc($getRefineCategory));
	
	
	
	// get keywords
	$pieces = explode(" ", strip_tags($_GET['ps']));
	$kp = count($pieces);
	// reset pieces
	$pluspieces = '';
	for ($pi=0;$pi<$kp;$pi++) {
	$pluspieces .= $pieces[$pi].' ';
	}
	$pluspieces = rtrim($pluspieces, " ");
	
	// change refine prices inaccordance with selected refine category
	$extracondition = '';
		if (isset($_GET['pscat'])){
		$extracondition .= " AND prodCategory = ".quote_smart($_GET['pscat'])."";
		}
	
	// output search results
	if ($indcount == 0) {
	$sql = "SELECT prodPrice, ( (1.3 * (MATCH(prodName) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) + (0.6 * (MATCH(prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) ) AS relevance FROM affiliSt_products1 WHERE ( MATCH(prodName,prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE) ) $extracondition HAVING relevance > 0 ORDER BY prodPrice DESC LIMIT 0,1";
	} else {
	$sql = "SELECT prodPrice, MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") AS relevance FROM affiliSt_products1 WHERE MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") $extracondition HAVING relevance > 0 ORDER BY prodPrice DESC LIMIT 0,1";
	}

	$getRefinePrice = mysql_query($sql, $databaseConnect) or die(mysql_error());
	$refinePrice = mysql_fetch_assoc($getRefinePrice);
	$highprice = $refinePrice['prodPrice'];
	if ($indcount == 0) {
	$sql = "SELECT prodPrice, ( (1.3 * (MATCH(prodName) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) + (0.6 * (MATCH(prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) ) AS relevance FROM affiliSt_products1 WHERE ( MATCH(prodName,prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE) ) $extracondition HAVING relevance > 0 ORDER BY prodPrice ASC LIMIT 0,1";
	} else {
	$sql = "SELECT prodPrice, MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") AS relevance FROM affiliSt_products1 WHERE MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") $extracondition HAVING relevance > 0 ORDER BY prodPrice ASC LIMIT 0,1";
	}

	$getRefineLowPrice = mysql_query($sql, $databaseConnect) or die(mysql_error());
	$refineLowPrice = mysql_fetch_assoc($getRefineLowPrice);
	$lowprice = $refineLowPrice['prodPrice'];




	if (($lowprice + 50.00) < $highprice) {
	$divideprice = ($highprice - $lowprice) / 5;
	
	if (isset($_GET['pscat'])) {
	$pscatvar = '&pscat='.str_replace(" ", "+", $_GET['pscat']);
	} else {
	$pscatvar = '';
	}
	
	if (isset($_GET['rshow'])) {
	$rshow = '&rshow=all';
	} else {
	$rshow = '';
	}
	
	$box_content->assign("PRICEREFLINKDATA",$installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).$pscatvar.'&pslow='.$lowprice.'&pshigh='.ceil($lowprice + $divideprice).$rshow);
	$box_content->assign("PRICEREFINE",$row_product['prodCurrency'].$lowprice.' - '.$row_product['prodCurrency'].ceil($lowprice + $divideprice));
	$box_content->parse("prod.refine.priceli");
	$box_content->assign("PRICEREFLINKDATA",$installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).$pscatvar.'&pslow='.ceil($lowprice + $divideprice).'&pshigh='.ceil($lowprice + ($divideprice * 2)).$rshow);
	$box_content->assign("PRICEREFINE",$row_product['prodCurrency'].ceil($lowprice + $divideprice).' - '.$row_product['prodCurrency'].ceil($lowprice + ($divideprice * 2)));
	$box_content->parse("prod.refine.priceli");
	$box_content->assign("PRICEREFLINKDATA",$installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).$pscatvar.'&pslow='.ceil($lowprice + ($divideprice * 2)).'&pshigh='.ceil($lowprice + ($divideprice * 3)).$rshow);
	$box_content->assign("PRICEREFINE",$row_product['prodCurrency'].ceil($lowprice + ($divideprice * 2)).' - '.$row_product['prodCurrency'].ceil($lowprice + ($divideprice * 3)));
	$box_content->parse("prod.refine.priceli");
	$box_content->assign("PRICEREFLINKDATA",$installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).$pscatvar.'&pslow='.ceil($lowprice + ($divideprice * 3)).'&pshigh='.ceil($lowprice + ($divideprice * 4)).$rshow);
	$box_content->assign("PRICEREFINE",$row_product['prodCurrency'].ceil($lowprice + ($divideprice * 3)).' - '.$row_product['prodCurrency'].ceil($lowprice + ($divideprice * 4)));
	$box_content->parse("prod.refine.priceli");
	$box_content->assign("PRICEREFLINKDATA",$installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).$pscatvar.'&pslow='.ceil($lowprice + ($divideprice * 4)).'&pshigh='.ceil($lowprice + ($divideprice * 5)).$rshow);
	$box_content->assign("PRICEREFINE",$row_product['prodCurrency'].ceil($lowprice + ($divideprice * 4)).' - '.$row_product['prodCurrency'].ceil($lowprice + ($divideprice * 5)));
	$box_content->parse("prod.refine.priceli");
	}

		
	
	
		$box_content->parse("prod.refine");
	}
	
	
	
	
	
	
	
	
	
	

// pinch column values from head
$totalColumns = $pPerPage[2];
$columnCount = 0;
$productCount = 0;

        do {
		
			
		// get titles
		$getTitles = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'feedMemory".$row_product['prodDB']."'");
		$allTitles = mysql_fetch_assoc($getTitles);
		$listTitles = explode("-:-", $allTitles['value']);
		
		// thumb image
		if ($row_product['prodImageSmall'] == NULL) {
		$thumbImage = $row_product['prodImageURL'];
		} else {
		$thumbImage = $row_product['prodImageSmall'];
		}
		
		
					// use merchant product ids
					if ($navOpt[12] == 1) {
					$theprodID = $row_product['merchantProdID'];
					} else {
					$theprodID = $row_product['dbProdID'];
					}
					if ($navOpt[7] == 1) {
					// html perma
					$prodLink = $installDir['value'].'product/'.$row_product['prodDB'].'/'.$theprodID.'/'.urltxt($row_product['prodName']).'.html';
					$savelink = $installDir['value'].'saveproduct/'.$row_product['prodDB'].'/'.$theprodID.'/'.urltxt($row_product['prodName']).'.html';
					$box_content->assign("IMAGELINK",$installDir['value'].'img/'.$row_product['prodDB'].'/'.$row_product['dbProdID'].'.jpg');
					} else {
					// php link
					$prodLink = $installDir['value'].'index.php?case=product&proddb='.$row_product['prodDB'].'&pid='.$theprodID;
					$savelink = $installDir['value'].'index.php?case=product&proddb='.$row_product['prodDB'].'&pid='.$theprodID.'&savelink=true';
					$box_content->assign("IMAGELINK",$thumbImage);
					}
					$box_content->assign("PRODLINK",$prodLink);
					
					// add to saved list link
					$box_content->assign("SAVELINK",'<a href="'.$savelink.'" rel="nofollow">+ Add to my saved list</a><br />');
					
					$box_content->assign("GOLINK",$installDir['value'].'go.php?proddb='.$row_product['prodDB'].'&amp;l='.$row_product['dbProdID']);
					
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[21];
						} else {
						$theTitle = '';
						}
					$box_content->assign("NAME",$theTitle.$row_product['prodName']);
					
					if ($prodOptions[0] == 1 && $row_product['merchant'] != '') {
					$box_content->assign("MERCHANT",'<span class="styleProdMerchant">'.$row_product['merchant'].'</span><br />');
					}
					if ($prodOptions[1] == 1 && $row_product['merchantProdID'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[19];
						} else {
						$theTitle = '';
						}
					$box_content->assign("PRODID", '<span class="styleProdID">'.$theTitle.$row_product['merchantProdID'].'</span><br />');
					} else {
					$box_content->assign("PRODID",'');
					}
					if ($prodOptions[2] == 1 && $row_product['prodCategory'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[20];
						} else {
						$theTitle = '';
						}
					$box_content->assign("PRODCAT",'<span class="styleProdCategory">'.$theTitle.$row_product['prodCategory'].'</span><br />');
					} else {
					$box_content->assign("PRODCAT",'');
					}
					if ($prodOptions[3] == 1 && $row_product['prodBrand'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[22];
						} else {
						$theTitle = '';
						}
					$box_content->assign("BRAND",'<span class="styleProdBrand">'.$theTitle.$row_product['prodBrand'].'</span><br />');
					} else {
					$box_content->assign("BRAND",'');
					}
					if ($prodOptions[4] == 1 && $row_product['prodPromoText'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[24];
						} else {
						$theTitle = '';
						}
					$box_content->assign("PROMO",'<span class="styleProdPromo">'.$theTitle.$row_product['prodPromoText'].'</span><br />');
					} else {
					$box_content->assign("PROMO",'');
					}
					if ($prodOptions[5] == 1 && $row_product['prodDescription'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[23];
						} else {
						$theTitle = '';
						}
					$box_content->assign("DESCRIPTION",'<span class="styleProdDescription">'.$theTitle.$row_product['prodDescription'].'</span><br />');
					} else {
					$box_content->assign("DESCRIPTION",'');
					}
					if ($prodOptions[6] == 1 && $row_product['prodPrice'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[27];
						} else {
						$theTitle = '';
						}
						if ($row_product['prodPrice'] == 0.00) {
						$box_content->assign("PRICE",$theTitle.'<span class="styleProdPrice">N/A</span><br />');
						} else {
						$box_content->assign("PRICE",$theTitle.'<span class="styleProdPrice">'.$row_product['prodCurrency'].$row_product['prodPrice'].'</span><br />');
						}
					} else {
					$box_content->assign("PRICE",'');
					}
					if ($prodOptions[7] == 1 && $row_product['extraFieldA'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[28];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDA",'<span class="singleProdDescription">'.$theTitle.$row_product['extraFieldA'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDA",'');
					}
					if ($prodOptions[8] == 1 && $row_product['extraFieldB'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[29];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDB",'<span class="singleProdDescription">'.$theTitle.$row_product['extraFieldB'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDB",'');
					}
					if ($prodOptions[9] == 1 && $row_product['extraFieldC'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[30];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDC",'<span class="singleProdDescription">'.$theTitle.$row_product['extraFieldC'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDC",'');
					}
					if ($prodOptions[10] == 1 && $row_product['extraFieldD'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[31];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDD",'<span class="singleProdDescription">'.$theTitle.$row_product['extraFieldD'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDD",'');
					}
					if ($prodOptions[11] == 1 && $row_product['extraFieldE'] != '') {
						if ($prodOptions[12] == 1) {
						$theTitle = $listTitles[32];
						} else {
						$theTitle = '';
						}
					$box_content->assign("EXTRAFIELDE",'<span class="singleProdDescription">'.$theTitle.$row_product['extraFieldE'].'</span><br />');
					} else {
					$box_content->assign("EXTRAFIELDE",'');
					}
					if ($prodOptions[13] == 1 && $listTitles[33] != '') {
					$box_content->assign("MERCHANTLOGO",'<a href="'.$installDir['value'].'go.php?proddb='.$row_product['prodDB'].'&amp;l='.$row_product['dbProdID'].'" rel="nofollow" target="_blank"><img src="'.$installDir['value'].$listTitles[33].'" alt="'.$row_product['merchant'].'" border="0" /></a><br />');
					} else {
					$box_content->assign("MERCHANTLOGO",'');
					}
					
					
					if ($navOpt[13] == 1) {
					// get comments
					$getComments = mysql_query("SELECT * FROM affiliSt_comments WHERE attachedID = '".$row_product['prodName']."' AND approve = '1' AND section = 'products' ORDER BY date DESC");
					$comments = mysql_fetch_assoc($getComments);
					// total comments
					$sql = "SELECT count(*) as numRows FROM affiliSt_comments WHERE  attachedID = '".$row_product['prodName']."' AND approve = '1' AND section = 'products'";
					$query = mysql_query($sql);
					$aRow = mysql_fetch_array($query);
					//echo $aRow[numRows]
					
					$totalProdRating = 0;
						do {
						$totalProdRating = $totalProdRating + $comments['rating'];
						} while ($comments = mysql_fetch_assoc($getComments));
					
						if ($aRow[numRows] != 0) {
						$prodRating = $totalProdRating / $aRow[numRows];
						$prodRating = round($prodRating);
						}
					
						if ($aRow[numRows] == 0) {
						$box_content->assign("RATING",'<a href="'.$prodLink.'">Review this product</a><br />');
						} else {
						$box_content->assign("RATING",'<img src="'.$installDir['value'].'skins/'.$configSkin['value'].'/styleImages/'.$prodRating.'star.gif" width="84" height="15" alt="Rating: '.$prodRating.'" align="left" /> (<a href="'.$prodLink.'">'.$aRow[numRows].' reviews</a>)<br />');
						}
					
					
						if ((($prodOptions[13] == 1 && $listTitles[33] != '') || ($prodOptions[0] == 1 && $row_product['merchant'] != ''))) {
						// merchant comments
						$getMerchantComments = mysql_query("SELECT * FROM affiliSt_comments WHERE attachedID = '".urltxt($row_product['merchant'])."' AND approve = '1' AND section = 'stores' ORDER BY date DESC");
						$merchantComments = mysql_fetch_assoc($getMerchantComments);
						// total comments
						$sql = "SELECT count(*) as numRows FROM affiliSt_comments WHERE attachedID = '".urltxt($row_product['merchant'])."' AND approve = '1' AND section = 'stores'";
						$query = mysql_query($sql);
						$aRow = mysql_fetch_array($query);
						//echo $aRow[numRows]
						
						$totalMerchantRating = 0;
							do {
							$totalMerchantRating = $totalMerchantRating + $merchantComments['rating'];
							} while ($merchantComments = mysql_fetch_assoc($getMerchantComments));
						
							if ($aRow[numRows] != 0) {
							$merchantRating = $totalMerchantRating / $aRow[numRows];
							$merchantRating = round($merchantRating);
							}
						
							if ($navOpt[7] == 1) {
							// html perma
							$merchantLink = $installDir['value'].'stores/'.urltxt($row_product['merchant']).'.html';
							} else {
							// php link
							$merchantLink = $installDir['value'].'index.php?case=stores&merchant='.urltxt($row_product['merchant']);
							}
							if ($aRow[numRows] == 0) {
							$box_content->assign("MERCHANTRATING",'<a href="'.$merchantLink.'">Review this store</a><br />');
							} else {
							$box_content->assign("MERCHANTRATING",'<img src="'.$installDir['value'].'skins/'.$configSkin['value'].'/styleImages/'.$merchantRating.'tic.gif" width="84" height="15" alt="Rating: '.$merchantRating.'" /><br />(<a href="'.$merchantLink.'">'.$aRow[numRows].' reviews</a>)<br />');
							}
						} else {
							$box_content->assign("MERCHANTRATING",'');
						}
					}
					
					
					
					$box_content->assign("INSTALLDIR",$installDir['value']);
					$box_content->assign("SKIN",$configSkin['value']);
					$box_content->assign("ENDROW","");
					
					
					
					$columnCount++;
					$productCount++;
					if ($columnCount == $totalColumns && $productCount != min($startRow_product+$maxRows_product, $totalRows_product)) {
					$box_content->assign("ENDROW","</tr>\n<tr>");
					$columnCount = 0;
					}
					
					$box_content->parse("prod.td");
		
        } while ($row_product = mysql_fetch_assoc($product));


$box_content->parse("prod");
$box_content = $box_content->text("prod");


} else {
$box_content->parse("noprod");
$box_content = $box_content->text("noprod");
}

}
?>